package base.exa11_object;

/**
 * 一个类想要能被clone，需要实现Cloneable接口
 */
public class ObjectCloneStudy implements Cloneable {

    /**
     * 成员变量name
     */
    public String name;

    public static void main(String[] args) throws CloneNotSupportedException {
        // 这里演示如何调用父类的Clone达到克隆的目的
        ObjectCloneStudy objectStudy = new ObjectCloneStudy();
        objectStudy.name = "我被克隆了";
        System.out.println(objectStudy.cloneTest().toString());
    }

    /**
     * Object类的clone方法测试
     * @return
     * @throws CloneNotSupportedException
     */
    public Object cloneTest() throws CloneNotSupportedException {
        return super.clone();
    }

    /**
     * 重写Object的toString方法
     * @return
     */
    public String toString() {
        return name;
    }

}
